package com.wifi.game.servlet;

import com.alibaba.fastjson.JSON;
import com.wifi.annotation.ShenZhouWifiMethod;
import com.wifi.game.entity.GameEntity;
import com.wifi.game.service.GameService;
import com.wifi.game.service.GameServiceImp;
import com.wifi.unti.PageInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/game/find")
public class GameServlet extends HttpServlet {
    GameService gameService=new GameServiceImp();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String pageSizestr = request.getParameter("pageSize");
        String pageNumstr = request.getParameter("pageNum");
        String typestr = request.getParameter("type");
                        //找全部的  count
        int count =(int)  gameService.count();
        PageInfo pageInfo=new PageInfo(pageNumstr,pageSizestr,count);
                                                  // 找  全部 list  分页
        List<Object> list = gameService.findAll(pageInfo.getStart(),pageInfo.getPageSize());
        System.out.println(list);
        pageInfo.setList(list);
        response.getWriter().write(JSON.toJSONString(pageInfo));
    }




    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/game/list/gameList.jsp").forward(request,response);
    }
}


